package com.seal.yoyoshop.adminweb;

import com.seal.yoyoshop.bin.Goods;
import com.seal.yoyoshop.service.GoodsService;
import com.seal.yoyoshop.service.impl.GoodsServiceImpl;
import com.seal.yoyoshop.util.PageUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GoodListServlet", value = "/admin/goodsList")
public class GoodListServlet extends HttpServlet {

    private GoodsService goodsService = new GoodsServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setAttribute("flag",3);

        String statusstr = request.getParameter("status");
        Integer status = Integer.parseInt(statusstr);
        String pagestr = request.getParameter("page");
        Integer page = Integer.parseInt(pagestr);
        String sizestr = request.getParameter("size");
        Integer size = Integer.parseInt(sizestr);
        request.setAttribute("status",0);
        if(status == 0){
            List<Goods> goodsList = goodsService.getGoodList(page,size);
            request.setAttribute("goodsList",goodsList);
//            分页
            long count = goodsService.getGoodsCount();
            String pageInfo = PageUtil.getPageTool(request, count, page, size);
            request.setAttribute("pageTool",pageInfo);
        }else {
            List<Goods> goodsList = goodsService.getGoodsListByHotType(status,page,size);
            request.setAttribute("goodsList",goodsList);
            //            分页
            long count = goodsService.getCountByHotType(status);
            String pageInfo = PageUtil.getPageTool(request, count, page, size);
            request.setAttribute("pageTool",pageInfo);
        }

        request.getRequestDispatcher("/admin/goods_list.jsp").forward(request,response);
    }
}
